package com.quanshu.exchange.support.api;

import com.quanshu.change.login.entity.CountryFlagEntity;
import com.quanshu.exchange.support.entity.UserEntity;
import com.quanshu.exchange.support.entity.VersionEntity;
import com.quanshu.exchange.support.net.BaseResponse;

import java.util.List;

import io.reactivex.Observable;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.POST;

/**
 * 登录注册模块的接口
 */
public interface LoginInterface {


    /**
     * 登录
     *
     * @param apiKey
     * @param phone
     * @param password
     * @return
     */
    @FormUrlEncoded
    @POST("index.php?model=api&controller=api_user&action=login")
    Observable<BaseResponse<UserEntity>> doLogin(@Field("apikey") String apiKey,
                                                 @Field("mobile") String phone,
                                                 @Field("password") String password);

    /**
     * @param apiKey
     * @param user_id
     * @param phone
     * @param token
     * @return
     */
    @FormUrlEncoded
    @POST("index.php?controller=api_user&action=autoLogin")
    Observable<BaseResponse<UserEntity>> autoLogin(@Field("apikey") String apiKey,
                                                   @Field("user_id") int user_id,
                                                   @Field("phone") String phone,
                                                   @Field("token") String token);


    /**
     * 获取国家列表
     *
     * @param apiKey
     * @return
     */
    @FormUrlEncoded
    @POST("index.php?model=api&controller=api_user&action=getCountryList")
    Observable<BaseResponse<List<CountryFlagEntity>>> getCountryList(@Field("apikey") String apiKey);

    /**
     * 注册
     *
     * @param apiKey
     * @param phone
     * @param countryid
     * @param smscode
     * @param referr
     * @return
     */
    @FormUrlEncoded
    @POST("index.php?model=api&controller=api_user&action=register")
    Observable<BaseResponse<UserEntity>> doRegister(@Field("apikey") String apiKey,
                                                    @Field("countryid") String countryid,
                                                    @Field("phone") String phone,
                                                    @Field("smscode") String smscode,
                                                    @Field("referr") String referr);

    /**
     * 发送短信
     *
     * @param apiKey
     * @param phone
     * @return
     */
    @FormUrlEncoded
    @POST("index.php?model=api&controller=api_user&action=sendSmsMsg")
    Observable<BaseResponse> doSendSms(@Field("apikey") String apiKey,
                                       @Field("phone") String phone);


    /**
     * 修改登录密码
     *
     * @param apiKey
     * @param memberid
     * @param oldPasswd
     * @param newPasswd
     * @return
     */
    @FormUrlEncoded
    @POST("index.php?controller=api_user&action=editLoginPwd")
    Observable<BaseResponse> editLoginPwd(@Field("apikey") String apiKey,
                                          @Field("memberid") String memberid,
                                          @Field("oldPasswd") String oldPasswd,
                                          @Field("newPasswd") String newPasswd);

    /**
     * 设置支付密码
     *
     * @param apiKey
     * @param memberid
     * @param payPasswd
     * @param repayPasswd
     * @param smscode
     * @return
     */
    @FormUrlEncoded
    @POST("index.php?model=api&controller=api_user&action=setTransPasswd")
    Observable<BaseResponse> setTransPasswd(@Field("apikey") String apiKey,
                                            @Field("memberid") String memberid,
                                            @Field("payPasswd") String payPasswd,
                                            @Field("repayPasswd") String repayPasswd,
                                            @Field("smscode") String smscode,
                                            @Field("phone") String phone);

    /**
     * 牛兑换昵称修改
     *
     * @param memberid ​账号
     * @param nickname ​新昵称
     * @return
     */
    @FormUrlEncoded
    @POST("/index.php?model=api&controller=api_user&action=updateNickName")
    Observable<BaseResponse> updateNickName(@Field("apikey") String apiKey,
                                            @Field("memberid") String memberid,
                                            @Field("nickname") String nickname);

    /**
     * 获取新版本
     *
     * @return
     */
    @GET("api_user/getNewVersion")
    Observable<BaseResponse<VersionEntity>> getNewVersion();

    /**
     * 退出登录
     *
     * @return
     */
    @GET("index.php?controller=api_user&action=loginout")
    Observable<BaseResponse> logOut();

    /**
     * 更改登录密码
     *
     * @param apiKey
     * @param phone
     * @return
     */
    @FormUrlEncoded
    @POST("index.php?model=api&controller=api_user&action=editLoginPwd")
    Observable<BaseResponse> alterLoginPwd(@Field("apikey") String apiKey,
                                           @Field("phone") String phone,
                                           @Field("sms_code") String code);

}
